<!doctype html>
<html>

<head>
    <title></title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <meta name="format-detection" content="telephone=yes" />
    <link rel="stylesheet" href="../res/css/weui.css" />
    <link rel="stylesheet" href="../res/css/weuix.css" />
    <link rel="stylesheet" href="../res/css/mp_common.css" />
    <link rel="stylesheet" href="../res/css/common.css" />
    <script src="../res/js/zepto.min.js"></script>
    <script src="../res/js/zepto.weui.js"></script>
    <script src="../res/js/mp_common.js?v=1"></script>
    <script src="../res/js/qrcode.min.js"></script>
    <script src="../res/js/common.js"></script>
    <script src="../res/js/JsBarcode.all.min.js" type="text/javascript"></script>
</head>
<style>
    .weui-cells {
        font-size: 14px;
    }

    .weui-cell {
        margin-bottom: 0px;
    }

    .fixed-top {
        position: fixed;
        top: 0;
        width: 100%;
        z-index: 100;
    }

    .show_drug {
        height: 60px;
        margin-top: 10px;
    }

    .drug_img {
        width: 60px;
        height: 60px;
        float: left;
        border-radius: 10px;
    }

    .show_drug>div {
        padding-left: 10px;
        color: #000;
        float: left;
        height: 60px;
        width: 75%;
        line-height: 30px;
        position: relative;
    }

    .drug_price {
        position: absolute;
        top: 5px;
        right: 10px;
        color: #000;
        font-size: 19px;
    }

    .titleDiv {
        margin-top: 40px;
        background-color: #fff;
        display: flex;
        justify-content: space-between;
    }

    .titleDiv div {
        padding: 15px 20px;
    }

    #p_status {
        font-size: 20px;
        color: #353535;
        font-weight: bold;
        font-family: PingFang-SC-Medium;
    }

    #goSeeOrder {
        color: #4187F7;
        line-height: 30px;
    }

    #callShop {
        background-color: #fff;
        display: flex;
        justify-content: space-between;
        padding: 10px 0;
        flex-wrap: wrap;
    }

    #p_pat_name {
        font-size: 15px;
        color: #353535;
        font-weight: bold;
    }

    #p_pat_address {
        font-size: 15px;
        color: #353535;
        font-weight: bold;
    }

    #takePhoto {
        display: flex;
        margin: 0 auto;
        flex-wrap: wrap;
        width: 20%;
        justify-content: center;
    }

    .showDeliveryInfo {
        width: 90%;
        margin: 10px 5%;
        background-color: rgba(0, 0, 0, 0.06);
        color: #868686;
        font-size: 15px;
        /* height: 100px; */
        border-radius: 10px;
        display: flex;
        justify-content: center;
        flex-wrap: wrap;
        align-items: center;
    }
</style>

<body ontouchstart>
    <div class="fixed-top" style="padding: 7px 2px; background-color: #ffffff; font-size: 18px; ">
        <div class="weui-flex__item">
            <div class="placeholder">
                <span class="icon icon-109" style=" margin-left: 8px;" onclick="ToPage()"></span>
                <span style="padding-left: 33%;">订单信息</span>
            </div>
        </div>
    </div>
    <div class="titleDiv">
        <div id="p_status">待收货</div>
        <div id="goSeeOrder">查看原始处方 ></div>
    </div>
    <div id="div_dd_info">
        <div id="callShop">
            <div style="display: flex;">
                <img src="../res/images/link_people_icon.png" alt=""
                    style="width: 35px;height: 35px;padding: 20px 0px;padding-left: 20px;">
                <div>
                    <div id="p_pat_name" style="padding: 0px 5px;margin-top:10px">收货人</div>
                    <div id="p_pat_address" style="padding: 0px 5px;color: #868686;font-weight: 500;"></div>
                </div>
            </div>
            <a id="takePhoto" href="tel:400-0000-688">
                <img src="../res/images/link-phone.png" alt="" style="width: 40px;height: 40px;">
                <div style="width: 100%;text-align: center;color: #4187F7;font-size: 15px;">联系商家</div>
            </a>
        </div>
        <div class="weui-cells">
            <div class="weui-cell">
                <div class="weui-cell__bd" id="div_dd_dtl">
                </div>
            </div>
        </div>
        <div class="weui-cells">
            <div class="weui-cell">
                <div class="weui-cell__bd" id="div_dd_ls_info">
                    <p style="font-size: 12px;padding: 5px;border-bottom: 1px solid #F2F2F2;">订单信息</p>
                    <p style="font-size: 12px;padding: 5px;display: flex;justify-content: space-between;">
                        订单编号：<span style="margin-right: 10px;">1000880</span></p>
                    <p style="font-size: 12px;padding: 5px;display: flex;justify-content: space-between;">
                        下单时间：<span style="margin-right: 10px;">1000880</span></p>
                </div>
            </div>
        </div>
        <!-- <div class="weui-cells">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <p style="font-size: 13px;">
                        药品金额</p>
                </div>
                <div class="weui-cell__ft" style="font-size: 13px;" id="div_sum_price">
                    ￥19.9</div>
            </div>
            <div class="weui-cell" id="div_kd_yf">
                <div class="weui-cell__bd">
                    <p style="font-size: 13px;">
                        运费</p>
                </div>
                <div class="weui-cell__ft" style="font-size: 13px;" id="div_yf_price">
                    ￥0</div>
            </div>
        </div> -->
        <div style="color: #C9C9C9;text-align: center;padding: 60px 0 !important">如有疑问，可联系客服</div>
        <div class="weui-cells" style="margin-bottom: 10px;position: fixed;bottom: -10px;width: 100%;" id="pay_Btn">
            <div class="weui-cell" style="margin: 0;">
                <div class="weui-cell__bd">
                    <p style="font-size: 13px;">
                    </p>
                </div>
                <div class="weui-cell__ft" style="font-size: 13px; margin-left: 10px;" id="div_act_btn2">
                    <a href="javascript:;" class="weui-btn weui-btn_mini  bg-orange" style="width: 100px;color: #fff;"
                        onclick="Pay_indent();">继续支付</a>
                </div>
                <div class="weui-cell__ft" style="font-size: 13px; margin-left: 10px;" id="div_act_btn">
                    <a href="javascript:;" class="weui-btn weui-btn_mini  bg-orange" style="width: 100px;color: #fff;"
                        onclick="confirm_indent();">确认收货</a>
                </div>
            </div>
        </div>
    </div>
</body>

</html>
<script type="text/javascript">
    var prescription_id = "";
    var indent_state = "0";
    var user_id = getQst("user_id").trim();
    var openid = getQst("openid").trim();
    var isShow = getQst("showDeliveryInfo").trim();
    var orderDetail = {}; //一线药房订单详情状态
    var loc_x, loc_y;
    var inside = getQst('inside') //是否院内药房
    if(!inside || inside === 'false'){
        inside = false
    }else{
        inside = true
    }
    $(function () {
        prescription_id = getQst("prescription_id").trim();
        switchStateKey(inside)
        if (inside) {
            hisInsideOrder()
        }else{
            getOrderDetails()
        }
        // -------------------
        /* 复制 */
        $("#div_kd_info_msg").on("click", ".courier-btn", function () {
            var content = $(".courier-text").val();
            var message = null;
            console.log(content);
            var aux = document.createElement("input");
            aux.setAttribute("value", content);
            document.body.appendChild(aux);
            aux.select();
            document.execCommand("copy");
            document.body.removeChild(aux);
            if (message == null) {
                alert("复制成功");
            } else {
                alert(message);
            }
        });
    });

    function getOrderDetails() {
        //测试数据
        // let params={"order_num": 'LO20210412145657005'}
        let params = {
            "order_num": prescription_id
        }
        newAjaxPost("/h5/thirdParty/orderDetail", params, getInfoOk);
    }

    function hisInsideOrder() {
        let params = {
            id: prescription_id
        }
        newAjaxPost("/h5/lianjiang/his/getPrescriptionInfoById", params, getInfoOk)
    }

    //获取数据
    function getInfoOk(rstData) {
        var sum_price = 0,
            str_dd_dtl_html = "";
        $("#takePhoto").attr("href", `tel:${rstData.data.store_phone}`)
        if (isShow == 1) {
            newAjaxPost("/h5/thirdParty/queryDeliveryInfo", {
                "order_num": prescription_id
            }, (json) => {
                if (json.data.list) {
                    $("#callShop").html(`
                    <div class = "showDeliveryInfo" onclick="to_logistics();" >
                    <div style = "width: 100%;margin-left: 10px;" > 包裹 物流信息 </div>
                    <div style = "width: 100%;margin-left: 10px;display: flex;justify-content: space-between;">
                        <span style = "color: #4187F7;overflow:hidden;text-overflow: ellipsis;">${json.data.list[0].status}</span><span style="margin: 0 20px;">></span>
                    </div> 
                    <div style = "width: 100%;margin-left: 10px;" > ${json.data.list[0].time} </div>
                    </div >
                    <div style="display: flex;">    
                    	<img src="../res/images/site_icon.png" alt=""
                    		style="width: 35px;height: 35px;padding: 20px 0px;padding-left: 20px;">
                    	<div>
                    		<div id="p_pat_name" style="padding: 0px 5px;margin-top:10px">收货人</div>
                    		<div id="p_pat_address" style="padding: 0px 5px;color: #868686;font-weight: 500;"></div>
                    	</div>
                    </div>`)
                }
            })
        } else {}
        if (rstData.code == 1) {
            orderDetail = rstData.data
            loc_y = rstData.data.loc_y;
            loc_x = rstData.data.loc_x;
            // if (rstData.data.take_type == 1)
            // 	actToPage('user_dtl3.htm?prescription_id=' + prescription_id);
            if (rstData.data.indent_state == STwaitPay) {
                //10:未付款(待付款)
                $("#p_status").html("未付款");
            } else if (rstData.data.indent_state == STwaitTake) {
                //35:待自提
                $("#p_status").html("待自提");
            } else if (rstData.data.indent_state == STwaitSend) {
                //20:待发货
                $("#p_status").html("待发货");
                $("#takePhoto").hide()
            } else if (rstData.data.indent_state == STsended) {
                //30:已发货(待收货)
                $("#p_status").html("待收货");
            } else if (rstData.data.indent_state == STcancel) {
                //订单状态：0:已取消
                $("#p_status").html("已取消");
            } else if (rstData.data.indent_state == STfinished) {
                //40:已收货(已完成)
                $("#p_status").html("已完成");
            }
            // $("#p_status").html(rstData.rows[0].indent_state);
            if (isSpace(rstData.data.pat_name)) {
                rstData.data.pat_name = '未设置'
            }

            if (rstData.data.take_type == 1) {
                $("#takePhoto").hide()
                $("#p_pat_name").html(`${rstData.data.pat_name} ${rstData.data.pat_photo}`);
                // if (isSpace(rstData.data.address_detl)) {
                //     $("#p_pat_address").html("收货地址：未设置");
                // } else {
                $("#p_pat_address").html(rstData.data.address_name + " " + rstData.data.address_detl);
                // }
            } else {
                $("#p_pat_name").html(`${rstData.data.pat_name} ${rstData.data.pat_photo}`);
                // if (isSpace(rstData.data.pat_photo)) {
                //     $("#p_pat_address").html("收货地址：未设置");
                // } else {
                $("#p_pat_address").html(rstData.data.address_name);
                // }
            }
            console.log(rstData);

            $("#txt_logistics_name").val(rstData.data.logistics_name);
            $("#txt_logistics_no").val(rstData.data.logistics_no);
            $("#txt_logistics_cost").val(rstData.data.logistics_cost);
            $("#div_kd_info").hide();
            if (!isSpace(rstData.data.logistics_name)) {
                $("#div_kd_tx").hide();
                $("#div_kd_info").show();
                var kd_info_html = "";
                kd_info_html = kd_info_html + "<p style=\"font-size: 12px;\">您的订单已由" + rstData.data.logistics_name +
                    "承运</p>";
                //复制
                kd_info_html = kd_info_html + "<p style=\"font-size: 12px;  display: inline-block;\">运单号：" + rstData
                    .data.logistics_no + "</p>";
                kd_info_html = kd_info_html + "<input class=\"courier-text\" value=\"" + rstData.data.logistics_no +
                    "\" type=\"hidden\" />";
                kd_info_html = kd_info_html +
                    "<a href=\"javascript:;\" style=\"color: Blue;  color: #2b73cc;font-size: 13px;margin-left: 5px;\" class=\"courier-btn\">[复制]</a>";
                kd_info_html = kd_info_html + "<p style=\"font-size: 12px;\">发货时间：" + rstData.data.send_time + "</p>";
                $("#div_kd_info_msg").html(kd_info_html);
            }
            //通过处方详情查药品信息
            newAjaxPost("/h5/myInterrogation/getPrescriptioninfo", {
                "prescriptionNo": rstData.data.rp_id
            }, infoOk);


            function infoOk(res) {
                //跳转到查看原始处方页面
                $("#goSeeOrder").click(() => {
                    actToPage('inquiry_go_order.htm?order_id=' + res.data.prescriptionNo + '&id=' + res.data
                        .id + '&is_order=1');
                })

                if (res.code == 1) {
                    str_dd_dtl_html +=
                        '<div style="padding: 10px 10px;border-bottom: 1px solid #F2F2F2;display:flex;justify-content: space-between;">';
                    str_dd_dtl_html += '<span style="margin-right:20px;">' + orderDetail.group_name + '</span>';
                    str_dd_dtl_html +=
                        `<span style="margin-right:20px;color: #4187F7;" onclick="actToPage('user_dtl_map.htm?loc_x=${loc_x}&loc_y=${loc_y}')">查看地图</span>`;
                    str_dd_dtl_html += '</div>';
                    //西药列表
                    if(res.data) {
                        if (res.data.westernMedicineResqList != null) {
                            for (var i = 0; i < res.data.westernMedicineResqList.length; i++) {
                                str_dd_dtl_html += '<div class="show_drug">';
                                str_dd_dtl_html += '<img src="' + (isSpace(res.data.westernMedicineResqList[i].drugImg) ?
                                        "../res/images/medisen1.jpg" : res.data.westernMedicineResqList[i].drugImg) +
                                    '" class="drug_img">';
                                str_dd_dtl_html += '<div class="drug_num">';
                                str_dd_dtl_html += '<div class="drug_name">' + res.data.westernMedicineResqList[i]
                                    .drugName + '</div>';
                                str_dd_dtl_html +=
                                    '<div style="font-size:24rpx;display:flex;justify-content: space-between;">';
                                str_dd_dtl_html += '<span>' + res.data.westernMedicineResqList[i].detailsNum + res.data
                                    .westernMedicineResqList[i].drugPackagingUnit + '</span>';
                                str_dd_dtl_html += '<div style="margin-right:10px">x' + res.data.westernMedicineResqList[i]
                                    .detailsConsumption + '</div>';
                                str_dd_dtl_html += '</div>';
                                str_dd_dtl_html += '<div class="drug_price">￥' + res.data.westernMedicineResqList[i]
                                    .drugPrice + '</div>';
                                str_dd_dtl_html += '</div>';
                                str_dd_dtl_html += '</div>';
                            }
                        }
                        //中药列表 
                        else {
                            for (var i = 0; i < res.data.chineseMedicineResqList.length; i++) {
                                str_dd_dtl_html += '<div class="show_drug">';
                                str_dd_dtl_html += '<img src="' + (isSpace(res.data.chineseMedicineResqList[i].drugImg) ?
                                        "../res/images/medisen1.jpg" : res.data.chineseMedicineResqList[i].drugImg) +
                                    '" class="drug_img">';
                                str_dd_dtl_html += '<div class="drug_num">';
                                str_dd_dtl_html += '<div class="drug_name">' + res.data.chineseMedicineResqList[i]
                                    .drugName + '</div>';
                                str_dd_dtl_html +=
                                    '<div style="font-size:24rpx;display:flex;justify-content: space-between;">';
                                str_dd_dtl_html += '<span>' + res.data.chineseMedicineResqList[i].detailsConsumption +
                                    res.data.chineseMedicineResqList[i].detailsConsumptionUnit + '</span>';
                                str_dd_dtl_html += '<div style="margin-right:10px">x' + res.data.chineseMedicineResqList[i]
                                    .detailsConsumption + '</div>';
                                str_dd_dtl_html += '</div>';
                                str_dd_dtl_html += '<div class="drug_price">￥' + res.data.chineseMedicineResqList[i]
                                    .drugPrice + '</div>';
                                str_dd_dtl_html += '</div>';
                                str_dd_dtl_html += '</div>';
                            }
                        }
                        str_dd_dtl_html += '<div style="padding:10px;border-bottom: 1px solid #F2F2F2; text-align:right">';
                        str_dd_dtl_html +=
                            `<span style="color: #4187F7;" onclick="actToPage('inquiry_go_med.htm?id=' + ${res.data.id})">用药详情></span>`;
                        str_dd_dtl_html += '</div>';
                        str_dd_dtl_html +=
                            `<div style="padding:10px;border-bottom: 1px solid #F2F2F2;display:flex;justify-content: space-between;"><div>商品总金额</div><div>￥${rstData.data.indent_total}</div></div>`
                        str_dd_dtl_html +=
                            `<div style="padding:10px;border-bottom: 1px solid #F2F2F2;display:flex;justify-content: space-between;"><div>配送费</div><div>￥${orderDetail.logistics_cost}</div></div>`
                        str_dd_dtl_html += '<div style="padding:10px;display:flex;justify-content:right;">';
                        str_dd_dtl_html +=
                            `<span style="font-size: 15px;font-weight: bold;">应付总金额: ￥${rstData.data.indent_total}</span>`;
                        str_dd_dtl_html += '</div>';
                    }
                }
            }
            $("#div_dd_dtl").html(str_dd_dtl_html);

            var str_dd_ls_info = "";
            str_dd_ls_info += `<p style="font-size: 12px;padding: 5px;border-bottom: 1px solid #F2F2F2;">订单信息</p>
            <p style="font-size: 12px;padding: 5px;display: flex;justify-content: space-between;">
                        订单编号：<span style="margin-right: 10px;">${rstData.data.order_sn }</span></p>
            <p style="font-size: 12px;padding: 5px;display: flex;justify-content: space-between;">
                        下单时间：<span style="margin-right: 10px;">${rstData.data.create_time}</span></p>
            <p style="font-size: 12px;padding: 5px;display: flex;justify-content: space-between;">
                        支付时间：<span style="margin-right: 10px;">${rstData.data.payment_time}</span></p>`
            // if (rstData.data.pay_status == "1") {
            //     str_dd_ls_info = str_dd_ls_info + "<p style=\"font-size: 12px;\">支付状态：已支付</p>";
            // } else {
            //     str_dd_ls_info = str_dd_ls_info + "<p style=\"font-size: 12px;\">支付状态：未支付</p>";
            // }
            // str_dd_ls_info = str_dd_ls_info + "<p style=\"font-size: 12px;\">取药方式：" + (rstData.data.take_type == "1" ?
            //     "快递派送" : "上门自取") + "</p>";
            $("#div_dd_ls_info").html(str_dd_ls_info);
            // $("#div_sum_price").html("￥" + rstData.data.indent_total);  //药品总金额
            // $("#div_yf_price").html("￥" + rstData.data.logistics_cost);     //运费

            indent_state = rstData.data && rstData.data.indent_state;
            pay_status = rstData.data && rstData.data.pay_status;
            if (pay_status == 1) {
                // 已支付
                // $('#div_act_btn2').html("<a href=\"javascript:;\" class=\"weui-btn weui-btn_mini  bg-gray\" style=\"width:100px; color:#CCC;\" >已支付</a>");
                $('#div_act_btn2').html(
                    "<a href=\"javascript:;\" class=\"weui-btn weui-btn_mini  bg-red\" style=\"width:100px; color:#FFF;\" onclick=\"Cancel_indent()\">退款</a>"
                );
            } else {
                //未支付，不操作
                $("#div_act_btn a").css("pointer-events", "none");
                $('#div_act_btn a').css("background-color", "gray");
            }

            if (rstData.data.indent_state == 20) {
                //20:待发货
                $("#div_act_btn a").css("pointer-events", "none");
                $('#div_act_btn a').css("background-color", "gray");
                $("#div_act_btn").hide()
            } else if (rstData.data.indent_state == 30) {
                //30:已发货(待收货)
                $("#div_act_btn2").html(
                    // "<a href=\"javascript:;\" class=\"weui-btn weui-btn_mini bg-blue\" style=\"width:100px;\" onclick=\"to_logistics();\">查看物流</a>"
                    "<a></a>"
                );
            } else if (rstData.data.indent_state == 0) {
                //订单状态：0:已取消
                $("#div_act_btn2").html(
                    "<a href=\"javascript:;\" class=\"weui-btn weui-btn_mini  bg-gray\" style=\"width:100px; color:#CCC;\">已取消</a>"
                );
                $("#div_act_btn").hide()
            }
        } else {
            $("#p_status").html("无该订单信息");
            $("#div_dd_info").hide();
        }
    }


    //确认收货
    function confirm_indent(rstData) {
        $.modal({
            title: "确认收货吗",
            buttons: [{
                    text: "确认",
                    onClick: function () {
                        var pJson = {
                            "order_num": prescription_id,
                            "type": 2
                        };
                        newAjaxPost("/h5/thirdParty/saveOrder", pJson, function (rstData) {
                            console.log(rstData)
                            if (rstData.code == 1) {
                                showJSZ("收货成功");
                                actToPage('user_dtl4.htm?prescription_id=' + prescription_id +
                                    '&user_id=' + user_id);
                            } else {
                                showJSZ(rstData.msg);
                            }
                        });
                    }
                },
                {
                    text: "取消",
                    className: "default",
                    onClick: function () {

                    }
                },
            ]
        });
    }

    //跳转支付页面
    function Pay_indent() {
        //2020.04.08----------
        if (!isSpace(openid)) {
            actToPage('user_dtl5.htm?prescription_id=' + prescription_id + '&openid=' + openid);
        } else {
            actToPage('user_dtl5.htm?prescription_id=' + prescription_id + '&user_id=' + user_id);
        }
        //-------------------
    }

    //退款
    function Cancel_indent() {
        // $.confirm("您确定要退款吗?", "确认退款?", function() 
        // 	{
        //         // $.toast("退款成功!");
        //     }, function() {
        //         //取消操作
        //     });
        $.alert("退款请联系客服，客服热线：\r\n020-32640557", function () {
            return;
        });
    }

    function Cancel_indentOK(rstData) {
        console.log(rstData)
        var msg = rstData.msg;
        var str = msg.charAt(9);
        //退款成功，回到订单列表
        if (str == 1) {
            showJSZ("退款成功!，三秒后回到我的订单")
            setTimeout(function () {
                ToPage();
            }, 2000)
        }
    }

    //物流
    function to_logistics() {
        actToPage('user_logistics.htm?prescription_id=' + prescription_id + '&user_id=' + user_id);
    }

    //返回列表
    function ToPage() {
        goPageNo(-1);
    }
</script>